﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

using BodaNetCommunications.Utilities.ComTypes;

namespace BodaNetCommunications.Utilities.DataLibs
{
    public class ULongLib
    {
        public static ulong GetULongFromByteArray(byte[] source, int start, EndianType type = EndianType.ABCD)
        {
            return BitConverter.ToUInt64(ByteArrayLib.Get8ByteArray(source, start, type), 0);
        }

        public static ulong[] GetULongArrayFromByteArray(byte[] source, EndianType type = EndianType.ABCD)
        {
            ulong[] array = new ulong[source.Length / 8];
            for (int i = 0; i < source.Length / 8; i++)
            {
                array[i] = GetULongFromByteArray(source, 8 * i, type);
            }

            return array;
        }

        public static ulong[] GetULongArrayFromString(string val)
        {
            List<ulong> list = new List<ulong>();
            if (val.Contains(' '))
            {
                string[] array = Regex.Split(val, "\\s+", RegexOptions.IgnoreCase);
                string[] array2 = array;
                foreach (string value in array2)
                {
                    list.Add(Convert.ToUInt64(value));
                }
            }
            else
            {
                list.Add(Convert.ToUInt64(val));
            }

            return list.ToArray();
        }
    }
}